const { MOCK } = require('../utils').settings
const axios = require('../utils/axios')
const { error } = require('../utils/error')
const {
  mockLogin,
  mockUser,
  mockUserClose,
  mockNews,
  mockAuditNewsList,
  mockAudit,
  mockNewsList,
  mockPostBanner,
  mockNewsState,
  mockNewsComplaint,
  mockClassConfig,
  mockDeleteClass,
  mockAddClass,
  mockGetBanner,
  mockPutBanner,
  mockPostNewsComplaint
} = require('./mock/admin')
const apiError = (msg) => {
  error('50000', __dirname, msg)
}
exports.requestLogin = async (data = {}) => {
  let result = MOCK ? mockLogin : await axios.post('/adminLogin', data)
  // let result = await mockLogin
  if (!result) {
    apiError('requestLogin')
    result = mockLogin
  }
  return result
}
// admin - user
exports.requestUser = async (data = {}) => {
  let result = MOCK
    ? mockUser
    : await axios({
        method: 'get',
        url: '/adm/getUserList',
        data
      })
  // await axios('/adm/getUserList', {
  //   parmas: data
  // })
  // let result = await mockUser
  if (!result) {
    apiError('requestUser')
    result = mockUser
  }
  return result
}
// admin - userClose
exports.requestUserClose = async (data = {}) => {
  let result = MOCK
    ? mockUserClose
    : await axios.post('/adm/banOrReCover', data)
  // let result = await mockUserClose
  if (!result) {
    apiError('requestUserClose')
    result = mockUserClose
  }
  return result
}
// admin - AuditNewsList
exports.requestAuditNewsList = async (data = {}) => {
  let result = MOCK
    ? mockAuditNewsList
    : await axios.get('/adm/getAuditList', {
        params: data
      })
  // let result = await mockAuditNewsList
  if (!result) {
    apiError('requestAuditNewsList')
    result = mockAuditNewsList
  }
  return result
}
// admin - News
exports.requestNews = async (data = {}) => {
  let result = MOCK
    ? mockNews
    : await axios.get('/adm/getAuditContent', {
        params: data
      })
  // let result = await mockNews
  if (!result) {
    apiError('requestAuditNews')
    result = mockNews
  }
  return result
}
// admin - Audit
exports.requestAudit = async (data = {}) => {
  let result = MOCK
    ? mockAudit
    : await axios.post('/adm/submitAuditResult', data)
  // let result = await mockAudit
  if (!result) {
    apiError('requestAudit')
    result = mockAudit
  }
  return result
}
// admin - PostNewsAudit *
exports.requestPostNewsComplaint = async (data = {}) => {
  let result = MOCK
    ? mockPostNewsComplaint
    : await axios.post('/adm/replyFeedback', data)
  // let result = await mockPostNewsComplaint
  if (!result) {
    apiError('requestPostNewsComplaint')
    result = mockPostNewsComplaint
  }
  return result
}
// admin - NewsList
exports.requestNewsList = async (data = {}) => {
  let result = MOCK
    ? mockNewsList
    : await axios({
        method: 'get',
        url: '/adm/getContributeList',
        data
      })
  // let result = await mockNewsList
  if (!result) {
    apiError('requestNewsList')
    result = mockNewsList
  }
  return result
}
// admin - PostBanner
exports.requestPostBanner = async (data = {}) => {
  let result = MOCK ? mockPostBanner : await axios.post('/adm/setTopLine', data)
  // let result = await mockPostBanner
  if (!result) {
    apiError('requestPostBanner')
    result = mockPostBanner
  }
  return result
}
// admin - GetBanner
exports.requestGetBanner = async (data = {}) => {
  let result = MOCK
    ? mockGetBanner
    : await axios.get('/adm/getTopLineNews', { params: data })
  // let result = await mockGetBanner
  if (!result) {
    apiError('requestGetBanner')
    result = mockGetBanner
  }
  return result
}
// admin - PutBanner
exports.requestPutBanner = async (data = {}) => {
  let result = MOCK ? mockPutBanner : await axios.post('/adm/editTopLine', data)
  // let result = await mockPutBanner
  if (!result) {
    apiError('requestPutBanner')
    result = mockPutBanner
  }
  return result
}
// admin - NewsState
exports.requestNewsState = async (data = {}) => {
  let result = MOCK
    ? mockNewsState
    : await axios.post('/adm/deleteOrRecoverNews', data)
  // let result = await mockNewsState
  if (!result) {
    apiError('requestNewsState')
    result = mockNewsState
  }
  return result
}
// admin - NewsComplaint
exports.requestNewsComplaint = async (data = {}) => {
  let result = MOCK
    ? mockNewsComplaint
    : await axios.get('/adm/getFeedbackList', {
        params: data
      })
  // let result = await mockNewsComplaint
  if (!result) {
    apiError('requestNewsComplaint')
    result = mockNewsComplaint
  }
  return result
}
// admin - ClassConfig
exports.requestClassConfig = async () => {
  let result = MOCK
    ? mockClassConfig
    : await axios.get('/adm/getPlateAndClassAdmin')
  // let result = await mockClassConfig
  if (!result) {
    apiError('requestClassConfig')
    result = mockClassConfig
  }
  return result
}
// admin - DeleteClassState
exports.requestDeleteClass = async (data) => {
  let result = MOCK
    ? mockDeleteClass
    : await axios.post('/adm/deleteOrRecoverPlate', data)
  // let result = await mockDeleteClass
  if (!result) {
    apiError('requestDeleteClass')
    result = mockDeleteClass
  }
  return result
}
// admin - AddClass
exports.requestAddClass = async (data) => {
  let result = MOCK
    ? mockAddClass
    : await axios.post('/adm/addPlateOrClass', data)
  // let result = await mockAddClass
  if (!result) {
    apiError('requestAddClass')
    result = mockAddClass
  }
  return result
}
